package com.sxt.pro.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**  

* @Description:  拦截器配置

* @author xinxiaokang  

* @date 2020年9月10日 下午5:21:13

*/

@Configuration
public class WebConfigurer implements WebMvcConfigurer {
	
	 @Autowired
	  private LoginInterceptor loginInterceptor;
	
	 /**
	  * 注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
	  */
	  @Override
	  public void addInterceptors(InterceptorRegistry registry) {
		  registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
		  .excludePathPatterns("/sys/login", "/resources/**", "/index.html", 
				  "/login/login", "/resources/**","/sys/logout","/sys/loadNetworkByterminalNo",
				  "/sys/sendProduct","/sys/sendNormalProduct","/sys/sendSourceData","/sys/sendCultureData",
				  "/sys/sendProductData","/sys/sendPersonData","/sys/sendGuideData","/sys/sendNoticeMessage",
				  "/sys/knowDataByterminalNo","/sys/inclusiveDataByterminalNo","/login/getAbChinaDate",
				  "/sys/quaryLivePayDataByterminalNo","/sys/quarySurroundDataByterminalNo",
				  "/sys/quaryScreensByterminalNo","/waterFall/loadTreeJson","/pro/nowapi","/upload/**"
				  ,"/api/**");
	  }
	  
	  
		/**
		 *  跨域支持
		 */
		@Bean
		public WebMvcConfigurer corsConfigurer() {
			return new WebMvcConfigurer() {
				@Override
				public void addCorsMappings(CorsRegistry registry) {
					registry.addMapping("/**").allowedMethods("*");
				}
			};
		}
		
		/**
		 * 配置静态资源的，比如html，js，css，以及图片地址的储存等等
		 */
	    @Override
	    public void addResourceHandlers(ResourceHandlerRegistry registry) {
	        //和页面有关的静态目录都放在项目的static目录下，访问路径如：http://localhost:8081/static/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
	        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
	        //windows下访问图片地址
	        registry.addResourceHandler("/upload/**").addResourceLocations("file:D:/upload/");
		      //linux下访问图片地址
           //registry.addResourceHandler("/upload/**").addResourceLocations("file:/usr/local/images/");
	    }

	  
	  
	  

}
